import {createRouter, createWebHistory} from "vue-router";
import UserLayout from "@/views/UserLayout.vue";
import MerchantLayout from "@/views/MerchantLayout.vue";
import MerchantInfo from "@/views/merchant/MerchantInfo.vue";
import FansInteraction from "@/views/merchant/FansInteraction.vue";
import CommentMessage from "@/views/merchant/CommentMessage.vue";
import SystemMessage from "@/views/merchant/SystemMessage.vue";
import StoreManageList from "@/views/merchant/StoreManageList.vue";
import StoreManageDetails from "@/views/merchant/StoreManageDetails.vue";
import LaunchStorePage from "@/views/merchant/LaunchStorePage.vue";
import AdminLayout from "@/views/AdminLayout.vue";
import Audit from "@/views/admin/Audit.vue";
import DataAnalysis from "@/views/admin/DataAnalysis.vue";
import MerchantList from "@/views/admin/MerchantList.vue";
import OrdinaryUserList from "@/views/admin/OrdinaryUserList.vue";
import UserLoginPage from "@/views/UserLoginPage.vue";
import MerchantLoginPage from "@/views/MerchantLoginPage.vue";
import AdminLoginPage from "@/views/AdminLoginPage.vue";
import RecommendHomePage from "@/views/user/RecommendHomePage.vue";
import StoreDetailsPage from "@/views/user/StoreDetailsPage.vue";
import PersonalHomePage from "@/views/user/PersonalHomePage.vue";
import OthersHomePage from "@/views/user/OthersHomePage.vue";
import UserRegister from "@/views/UserRegister.vue";
import FavoriteListPage from "@/views/user/FavoriteListPage.vue";
import CategoryStores  from "@/views/user/CategoryStores.vue";
import DiscoveryPage from "@/views/user/DiscoveryPage.vue";
import HomePage  from "@/views/HomePage.vue";
import MerchantRegister from "@/views/MerchantRegister.vue";



// 定义路由关系
const routes = [
  {path: '/homePage', component: HomePage},  // 一级路由
  {path: '/userLoginPage', component: UserLoginPage},  // 一级路由
  {path: '/merchantLoginPage', component: MerchantLoginPage},  // 一级路由
  {path: '/adminLoginPage', component: AdminLoginPage},  // 一级路由
  {path: '/userRegisterPage', component: UserRegister},  // 一级路由
  {path: '/merchantRegister', component: MerchantRegister},  // 一级路由
  {
    path: '/',
    redirect: '/homePage',  // 重定向 要改为用户登录页（说明）
    component: HomePage,
    // 子路由
    children: [
      {path: '/userLoginPage', component: UserLoginPage},  // 二级路由
      {path: '/merchantLoginPage', component: MerchantLoginPage},  // 二级路由
      {path: '/userRegisterPage', component: UserRegister},
    ]
  },
  {
    path: '/',
    redirect: '/userLoginPage',  // 重定向 要改为用户登录页（说明）
    component: UserLayout,
    // 子路由
    children: [
      {path: '/user/recommendHomePage', component: RecommendHomePage},  // 二级路由
      {path: '/user/storeDetailsPage/:id', component: StoreDetailsPage},  // 二级路由
      {path: '/user/personalHomePage', component: PersonalHomePage},  // 二级路由
      {path: '/user/othersHomePage/:id', component: OthersHomePage},  // 二级路由
      {path: '/user/category/:id', component: CategoryStores},  // 二级路由
      {path: '/user/favoriteListPage', component: FavoriteListPage},  // 二级路由
      {path: '/user/DiscoveryPage', component: DiscoveryPage},
    ]
  },
  {
    path: '/',
    redirect: '/merchantLoginPage',  // 重定向 要改为商家登录页（说明）
    component: MerchantLayout,
    children: [
      {path: '/merchant/info', component: MerchantInfo},
      {path: '/merchant/fansInteraction', component: FansInteraction},
      {path: '/merchant/commentMessage', component: CommentMessage},
      {path: '/merchant/systemMessage', component: SystemMessage},
      {
        path: '/merchant/storeManageList',
        component: StoreManageList,
        children: [
          {
            path: ':id',
            component: StoreManageDetails,
            props: true, // 将路由参数传递给组件
            meta: { requiresAuth: true }, // 添加key属性确保组件重建
          },
        ]
      },
      {path: '/merchant/launchStorePage', component: LaunchStorePage},
    ]
  },
  {
    path: '/',
    redirect: '/adminLoginPage',  // 重定向 要改为管理员登录页（说明）
    component: AdminLayout,
    children: [
      {path: '/admin/audit', component: Audit},
      {path: '/admin/dataAnalysis', component: DataAnalysis},
      {path: '/admin/merchantList', component: MerchantList},
      {path: '/admin/ordinaryUserList', component: OrdinaryUserList},
    ]
  },
]

// 创建路由器
const router = createRouter({
  history: createWebHistory(), // 路由模式
  routes: routes
})

//导出暴露
export default router
